FROM openanolis/anolisos:8.6

LABEL \
	org.opencontainers.image.title="mariadb" \
        org.opencontainers.image.version="10.3.35-8.6"

RUN set -eux; \
	yum -y update; \
	yum -y install mariadb-server mariadb-backup wget; \
	yum clean all

ARG TARGETARCH

ENV GOSU_VERSION 1.14

RUN set -eux; \
        wget --timeout=5 --tries=10 -O /usr/local/bin/gosu "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH"; \
        wget --timeout=5 --tries=10 -O /usr/local/bin/gosu.asc "https://github.com/tianon/gosu/releases/download/$GOSU_VERSION/gosu-$TARGETARCH.asc"; \
        export GNUPGHOME="$(mktemp -d)"; \
        for server in $(shuf -e ha.pool.sks-keyservers.net \
        hkp://p80.pool.sks-keyservers.net:80 \
        pgp.mit.edu) ; do \
        gpg --keyserver "$server" --recv-keys B42F6819007F00F88E364FD4036A9C25BF357DD4 && break || : ; \
        done && \
        gpg --batch --verify /usr/local/bin/gosu.asc /usr/local/bin/gosu; \
        gpgconf --kill all; \
        rm -rf "$GNUPGHOME" /usr/local/bin/gosu.asc; \
        chmod +x /usr/local/bin/gosu; \
        gosu --version; \
        gosu nobody true

RUN set -eux; \
	rm -rf /var/lib/mysql; \
	mkdir -p /var/lib/mysql /var/run/mysqld; \
	chown -R mysql:mysql /var/lib/mysql /var/run/mysqld; \
	chmod 777 /var/run/mysqld; \
	mkdir /docker-entrypoint-initdb.d; \
	find /etc/my.cnf.d/ -name '*.cnf' -print0 \
		| xargs -0 grep -lZE '^(bind-address|log|user\s)' \
		| xargs -rt -0 sed -Ei 's/^(bind-address|log|user\s)/#&/'; \
	printf "[mariadb]\nhost-cache-size=0\nskip-name-resolve\n" > /etc/my.cnf.d/05-skipcache.cnf; \
	ln -s /usr/libexec/mysqld /usr/bin; \
	mysqld --version; \
	mysql --version

ENV MYSQL_MAJOR 8.0

ENV MYSQL_VERSION 8.0.30

VOLUME /var/lib/mysql

COPY healthcheck.sh /usr/local/bin/healthcheck.sh

COPY docker-entrypoint.sh /usr/local/bin/

RUN set -eux; \
	ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh

ENTRYPOINT ["docker-entrypoint.sh"]

EXPOSE 3306 33060

CMD ["mysqld"]
